package com.heima.article.listener;

import com.heima.article.service.ApHotArticlesService;
import com.heima.common.constants.message.HotArticleConstants;
import com.heima.common.util.JsonUtils;
import com.heima.model.article.dtos.ArticleBehaviorStreamMsg;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class BehaviorStreamConsumer {
    @Autowired
    private ApHotArticlesService hotArticlesService;
    @KafkaListener(topics = HotArticleConstants.HOT_ARTICLE_SCORE_CONSUMER_TOPIC)
    public void onMessage(ConsumerRecord<String, String> consumerRecord){
        log.info("收到流处理结果消息:{}", consumerRecord.value());

        ArticleBehaviorStreamMsg streamMsg = JsonUtils.toBean(consumerRecord.value(), ArticleBehaviorStreamMsg.class);


        hotArticlesService.updateArticleScore(streamMsg);
    }

}